/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { Component } from "react";
import KbSourceList from "@/components/KbSource";
import KbSourceAdd from "@/components/KbSource/add";
import { Tabs } from "antd";

const { TabPane } = Tabs;

export default class OrderSource extends Component {
  constructor(props) {
    super(props);
    this.state = {
      activeKey: 'list',
    };
  }

  componentDidMount(){
    this.setState({
      activeKey: this.props.activeKey
    })
  }

  componentWillReceiveProps(nextProps){
    const { activeKey } = this.props
    if(activeKey !== nextProps.activeKey){
      this.setState({
        activeKey: nextProps.activeKey
      })
    }
  }

  changeKey = (key) => {
    this.setState({
      activeKey: key
    })
  }

  render() {
    const { activeKey } = this.state
    return (
      <>
        <Tabs activeKey={activeKey} onChange={this.changeKey}>
          <TabPane tab="已添加单号源" key="list">
            <KbSourceList />
          </TabPane>
          <TabPane tab="添加新单号源" key="add">
            <KbSourceAdd />
          </TabPane>
        </Tabs>
      </>
    )
  }
}
